﻿using Coomtools.commclass;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CYLScheck.UIcomm
{
    public partial class RegFrm : UIForm
    {
        private Declosedmainform declosemain;
        public RegFrm(Declosedmainform  decloseMainFrm)
        {
            InitializeComponent();
            declosemain = decloseMainFrm;
        }
        int Regpassword,newRegtxt;
        string Regdatetime;
            string[] RegdateArray;
        private void RegFrm_Load(object sender, EventArgs e)
        {
            this.Style = Gobleset.Gobel_userstyle;
            Tbox_username.Focus();
            
            uiLabel1.AutoSize = true;
             Regdatetime = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");
            uiLabel1.Text = Regdatetime;
          
          
            RegdateArray = Regdatetime.Split('-');

            foreach (var item in RegdateArray)
            {
                newRegtxt += Convert.ToInt32(item);
            }
            newRegtxt = newRegtxt *4321;
          
            uiLabel1.Text = newRegtxt.ToString();

            Regpassword = newRegtxt * 105;



        }
 private void  startReg()
        {

            HardwareInfo GetHardwareinf = new HardwareInfo();
           

            string regcpuid = "";
            regcpuid = GetHardwareinf.GetCpuID();

            string regdskid = "";
            regdskid = GetHardwareinf.GetFristHardDiskID();
            //macid 暂时不用与验证
            string regmacid = "";
            regmacid = GetHardwareinf.GetPhysicLocalMacAddr();

            IniFileEx iniwrite = new IniFileEx("loginset.ini");
            MyEncrypt encrypt = new MyEncrypt();
            iniwrite.Write("regstats", "regcpuid", encrypt.EncryptString(regcpuid));
            iniwrite.Write("regstats", "regdskid", encrypt.EncryptString(regdskid));
            iniwrite.Write("regstats", "regmacid", encrypt.EncryptString(regmacid));
            iniwrite.Write("regstats", "reguserid", Tbox_username.Text.Trim());

        }
        private void uiSymbolButton1_Click(object sender, EventArgs e)
        {
                     if (Tbox_username.Text=="")
            {
                UIMessageBox.ShowAsk("最好输入个用户名吧！随便打几个字也行！");
                Tbox_username.Focus();
                return;
            }
            
            if (Tbox_passcommand.Text=="")
            {
                UIMessageBox.ShowWarning("你没有输入注册号");
               
                Tbox_passcommand.Focus();
                    return;
            }
  
            
            if (Tbox_passcommand.Text.Trim()==Regpassword.ToString()|| Tbox_passcommand.Text.Trim() =="wanghaoqi16888")
            {
               
                
                try
                {

                    startReg();
                    UIMessageBox.ShowSuccess("注册成功，请重启主程序！");
                    //this.Close();

                    declosemain();
                    return;
                }
                catch (Exception)
                {
                    UIMessageBox.ShowError("注册中发生错误，注册失败！请重新注册！");
                    Tbox_passcommand.Text = "";
                    Tbox_passcommand.Focus();
                    return;
                    throw;
                }

               
            }

            else
            {
              UIMessageBox.ShowInfo("输入的注册不正确！请重新输入！");
                Tbox_passcommand.Text = "";
                Tbox_passcommand.Focus();
                    return;
            }
           

           
             
    

         
        }
    }
}
